package thread;
/**
 * 第二种创建线程的方式:单独定义线程任务
 * 定义任务:
 * 1:实现Runnable接口
 * 2:实现Callable接口(如果线程执行完毕后需要返回值时使用，多用于线程池)
 *
 */
public class ThreadDemo02 {
    public static void main(String[] args) {
        // 创建任务对象
        MyThreadRun myThreadRun = new MyThreadRun();
        Thread thread = new Thread(myThreadRun);
        thread.start();

        MyThreadRun2 myThreadRun2 = new MyThreadRun2();
        Thread thread2 = new Thread(myThreadRun2);
        thread2.start();
        System.out.println("程序结束");

        // 匿名内部类
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("修锁的~~~~");
                }
            }
        });
        t3.start();
    }
}
// 1 定义一个类，实现Runable接口 ，重写run方法，定义线程任务
class MyThreadRun implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("你是谁啊！！！！");
        }
    }
}
class MyThreadRun2 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("查水表的~~~");
        }
    }
}
